import {
  Controller,
  Get,
  Post,
  Put,
  Delete,
  Param,
  Body,
  Query,
} from '@nestjs/common';
import { StudentService } from './student.service';
import { Student } from './entities/student.entity';

@Controller('students')
export class StudentController {
  constructor(private readonly studentService: StudentService) {}

  @Get()
  async findAll(
    @Query('page') page: number,
    @Query('pageSize') pageSize: number
  ) {
    return this.studentService.findAll(page || 1, pageSize || 10);
  }

  @Get(':sno')
  findOne(@Param('sno') sno: string) {
    return this.studentService.findOne(sno);
  }

  @Post()
  create(@Body() student: Student) {
    return this.studentService.create(student);
  }

  @Put(':sno')
  update(@Param('sno') sno: string, @Body() student: Partial<Student>) {
    return this.studentService.update(sno, student);
  }

  @Delete(':sno')
  remove(@Param('sno') sno: string) {
    return this.studentService.delete(sno);
  }
}
